﻿using System;
using System.Net;

namespace Framework.Http
{
    public class HttpExtension
    {
        /// <summary>
        /// 获取错误的WEB网页
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public int GetUrlError(string url)
        {
            int num = 200;
            var request = (HttpWebRequest)WebRequest.Create(new Uri(url));
            ServicePointManager.Expect100Continue = false;
            try
            {
                (request.GetResponse()).Close();
            }
            catch (WebException exception)
            {
                if (exception.Status != WebExceptionStatus.ProtocolError)
                {
                    return num;
                }
                if (exception.Message.IndexOf("500 ", StringComparison.Ordinal) > 0)
                {
                    return 500;
                }
                if (exception.Message.IndexOf("401 ", StringComparison.Ordinal) > 0)
                {
                    return 401;
                }
                if (exception.Message.IndexOf("404", StringComparison.Ordinal) > 0)
                {
                    num = 404;
                }
            }
            return num;
        }
    }
}